package com.network.utils.demo.http;

import android.app.Application;
import android.content.pm.PackageManager;
import android.os.Build;


import com.network.retrofit.utils.NetWorkBaseUtil;
import com.network.retrofit.utils.NetWorkLogUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 项目创建人:
 * 创建人:fargo(罗)
 * Created by app on 2020/9/15  —————— 10:45
 * 作用: 请求参数等 基本配置
 * 备注:
 **/
public class ParamsUtil {

    public static Map<String, String> getParams() {
        Map<String, String> params= new HashMap<String, String>();
        return params;
    }

    public static Map<String, Object> getParamsObject() {
        Map<String, Object> params= new HashMap<String, Object>();
        return params;
    }


    /**
     * 输出参数信息
     */
    public static void showParam(Map<String, String> paramsInfo){
        if(paramsInfo==null)
        {
            NetWorkLogUtil.logE("输出参数为空");
            return;
        }
        NetWorkLogUtil.logE("AllParamsInfo", NetWorkBaseUtil.getInstance().getGson().toJson(paramsInfo));
    }


    /**
     * 设置参数
     * @param params
     * @param key
     * @param value
     */
    public static void setParam(Map<String, String> params, String key, String value) {
        params.put(key, value);
    }


    /**
     * 增加公共参数
     *
     * @param params
     */
    public static void setPublicParam(Map<String, String> params, Application application) {

        try {
            //params.put("app_release", application.getString(R.string.app_name));
            params.put("student_type", "1");
            params.put("app_release", "wencaixuetang");
            params.put("phone_type", "android");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                params.put("current_version", String.valueOf(application.getPackageManager().getPackageInfo(application.getPackageName(), 0).getLongVersionCode()));
            }else{
                params.put("current_version", String.valueOf(application.getPackageManager().getPackageInfo(application.getPackageName(), 0).versionCode));
            }

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

}
